import dayjs from 'dayjs'
//对比当前时间 返回剩余或者过期时间
export const getRemainOrExpires = computed(() => {
  return time => {
    if (!+time) return '-'
    const currentTime = dayjs().unix()
    const timeDiff = time - currentTime
    if (timeDiff > 3600) {
      return `${secondToDayHours(timeDiff)}`
    } else if (timeDiff < 3600 && timeDiff > 0) {
      // return `过期 ${secondToDayHours(-timeDiff)}`
      return '剩余不足一小时'
    } else {
      return '已到期'
    }
  }
})
// secondToDayHours
export const secondToDayHours = (
  second: number | string,
  type: 'full' | 'day' = 'full'
) => {
  second = +second // 转换为数字类型
  if (second < 86400) {
    const hours = Math.floor(second / 3600)
    return `${hours}小时`
  }
  const day = Math.floor(second / 86400)
  const remainingSeconds = second % 86400
  const hours = Math.floor(remainingSeconds / 3600)

  let str = `${day}天`
  if (type === 'day') return `${day}天`
  if (hours > 0) {
    str += `${hours}小时`
  }
  return str
}
